﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace PasswordControl
{
    /*
    *   Control_Program Class
    */
    public class Owners
    {
        static private Dictionary<string, Owners> owner_list = new Dictionary<string, Owners>();

        //group
        private string m_group = ControlProgram.GROUP_GENERAL;
        public string Group
        {
            get { return m_group; }
            set { m_group = value; }
        }
        //owner 
        public string Owner { get; set; }
        //username
        public string Username { get; set; }
        //password
        public string Password { get; set; }
        //field name
        public string Fieldname { get; set; }
        //field data
        public string Fielddata { get; set; }

        //constructor
        public Owners() { }
        public Owners(string new_owner, string new_username, string new_password, string new_field, string field_data, string new_group)
        {
            Owner = new_owner;
            Username = new_username;
            Password = new_password;
            Fieldname = new_field;
            Fielddata = field_data;
            m_group = new_group;
        }

        //add - create owner
        static public void AddOwner(string owner, string username, string password, string fieldname, string fielddata, string group)
        {
            Owners own_class = new Owners(owner, username, password, fieldname, fielddata, group);

            owner_list.Add(owner, own_class);
        }
        //add - only insert to dictionary
        static public void AddOwner(Owners newOwner)
        {
            owner_list.Add(newOwner.Owner, newOwner);
        }

        //add - Owners list
        static public void AddOwner(List<Owners> newOwners, bool clear)
        {
            if (clear) ClearList();
            foreach (Owners temp in newOwners)
            {
                owner_list.Add(temp.Owner, temp);
            }
        }

        //find
        static public Owners FindOwner(string owner)
        {
            try
            {
                return owner_list[owner];
            }
            catch
            {
                return null;
            }
        }

        //Exists - List
        static public bool Contains(List<Owners> data)
        {
            foreach (Owners temp in data)
                if (owner_list.ContainsKey(temp.Owner)) return true;
            return false;
        }

        //remove
        static public Boolean RemoveOwner(string owner)
        {
            return owner_list.Remove(owner);
        }

        //is empty
        static public Boolean IsEmpty()
        {
            if (owner_list.Count == 0) return true;
            return false;
        }

        //clear Owners
        static public void ClearList()
        {
            owner_list.Clear();
        }

        //get Owners names as list
        static public List<string> GetOwnersNames()
        {
            return owner_list.Keys.ToList<string>();
        }

        //get Owners as list
        static public List<Owners> GetOwners()
        {
            return owner_list.Values.ToList<Owners>();
        }
    }
}

 

